<template>
    <div class="page">
        <el-row style="padding-bottom: 10px;">
            <el-col :span="6">
                <el-input placeholder="关键字搜索">
                    <el-button slot="append" icon="el-icon-search"></el-button>
                </el-input>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24" style="padding-bottom: 10px;text-align: right;">
                <el-button size="small" type="primary" icon="el-icon-edit-outline" @click="openAddDrawer">添加</el-button>
                <el-button size="small" type="primary" icon="el-icon-edit" @click="openUpdateDrawer"
                           :disabled="selectRows.length!==1">编辑</el-button>
                <el-button size="small" type="primary" icon="el-icon-info" @click="openUpdateDrawer"
                           :disabled="selectRows.length!==1">详情</el-button>
                <el-button size="small" type="primary" icon="el-icon-delete" @click=""
                           :disabled="selectRows.length===0">删除</el-button>
            </el-col>
            <el-col :span="24" style="padding-bottom: 10px;">
                <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55" />
                    <el-table-column fixed prop="memberNo" label="会员编号" width="200"></el-table-column>
                    <el-table-column prop="memberName" label="姓名" width="200"></el-table-column>
                    <el-table-column prop="memberSex" label="性别" width="120"></el-table-column>
                </el-table>
            </el-col>
            <el-col :span="24" style="text-align: center;">
                <el-pagination background layout="prev, pager, next" :total="paginationCofig.total"
                               @size-change="sizeChange" :pageSize="paginationCofig.pageSize"
                               :currentPage.sync="paginationCofig.currentPage" @current-change="currentChange"
                               @prev-click="prevClick" @next-click="nextClick"></el-pagination>
            </el-col>
        </el-row>


        <!-- 新增 -->
        <el-drawer title="新增" :visible.sync="isAddDrawer" direction="rtl" :wrapperClosable="false"
                   :close-on-press-escape="false" :show-close="false">
            <el-row style="height: calc(100% - 42px);">
                <el-form :model="addForm" :rules="rules" ref="addForm" label-width="100px">
                    <el-form-item label="会员名称" prop="memberName">
                        <el-input v-model="addForm.memberName" placeholder="会员名称" style="width: 80%;"></el-input>
                    </el-form-item>
                    <el-form-item label="会员性别" prop="memberSex">
                        <el-select v-model="addForm.memberSex" placeholder="会员性别" style="width: 80%;">
                            <el-option label="女" value="0"></el-option>
                            <el-option label="男" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
            </el-row>
            <el-row style="height: 42px;text-align: right;border-top: 1px solid #e4e7ed;padding-top: 10px;">
                <el-button size="small" type="primary" icon="el-icon-check">保存</el-button>
                <el-button size="small" type="danger" icon="el-icon-close" @click="isAddDrawer=false">关闭</el-button>
            </el-row>
        </el-drawer>
        <!-- 编辑 -->
        <el-drawer title="编辑" :visible.sync="isUpdateDrawer" direction="rtl">
            <span>我来啦!</span>
        </el-drawer>
        <!-- 详情 -->
        <el-drawer title="详情" :visible.sync="isDetailDrawer" direction="rtl">
            <span>我来啦!</span>
        </el-drawer>

    </div>
</template>

<script>
import $api from '@/api/member'
export default {
    data() {
        return {
            /* 分页tiao */
            paginationCofig: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            /* 表格data */
            tableData: [],
            selectRows: [],
            /* 抽屉 */
            isAddDrawer: false,
            isUpdateDrawer: false,
            isDetailDrawer: false,

            /* 表单 */
            addForm: {
                memberName: '',
                memberSex: '',
            },
            rules: {
                memberName: [
                    { required: true, message: '请输入会员姓名', trigger: 'blur' },
                    { min: 3, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur' }
                ],
                memberSex: [
                    { required: true, message: '请选择会员性别', trigger: 'change' }
                ],
            }
        };
    },
    methods: {
        handleSelectionChange(val) {
            this.selectRows = val
        },
        /* 新增抽屉 */
        openAddDrawer() {
            this.isAddDrawer = true
        },
        /* 修改抽屉 */
        openUpdateDrawer() {
            this.isUpdateDrawer = true
        },
        /* 详情抽屉 */
        openDetailDrawer() {
            this.isDetailDrawer = true
        },
        /* 分页条-start */
        sizeChange(pageSize) {
            this.memberListPage()
        },
        currentChange(currentPage) {
            this.memberListPage()
        },
        prevClick(pageSize) {
            this.memberListPage()
        },
        nextClick(currentPage) {
            this.memberListPage()
        },
        /* api */

        memberListPage(query) {
            const currentPage = this.paginationCofig.currentPage
            const pageSize = this.paginationCofig.pageSize
            $api.memberListPage(currentPage, pageSize, query).then(data => {
                // console.log(data.data);
                this.paginationCofig.total = data.data.total

                this.tableData = data.data.list
            })

        }

    },
    mounted() {
        this.memberListPage()
    }
};
</script>